<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style type="text/css">
		p{
			display: inline-block;
		}
	</style>
</head>
<body>
	<p>
		<span></span>年
	</p>
	<p>
		<span></span>月
	</p>
	<p>
		<span></span>日
	</p>
	<p>
		<span></span>时
	</p>
	<p>
		<span></span>分
	</p>
	<p>
		<span></span>秒
	</p>
	<script type="text/javascript">

		let spans = document.querySelectorAll('p span')
	function time() {
		
		//获取当前时间 返回中国标准时间
		let date = new Date()
		console.log(date)

		let year = date.getFullYear() //返回年份
		let month = date.getMonth() + 1 //返回的月份是 0-11 要手动加一
		let day = date.getDate() //返回日期 1-31
		let hour = date.getHours() //返回0-2小时
		let minute = date.getMinutes() //返回0-59分钟
		let second = date.getSeconds() //秒 0-59秒
		let millisecond = date.getMilliseconds() //毫秒 0-999
		console.log(year, month, day, hour, minute, second, millisecond)


		
		spans[0].innerText = year 
		spans[1].innerText = month 
		spans[2].innerText = day 
		spans[3].innerText = hour 
		spans[4].innerText = minute 
		spans[5].innerText = second 
	}
		time()
		setInterval(time, 1000)
	</script>
</body>
</html>